const vscode = require('vscode');
const tips = require('./tipsData')



/**
 * 鼠标悬停提示，当鼠标停在package.json的dependencies或者devDependencies时，
 * 自动显示对应包的名称、版本号和许可协议
 * @param {*} document 
 * @param {*} position 
 * @param {*} token 
 */
function provideHover(document, position, token) {
    const word = document.getText(document.getWordRangeAtPosition(position));//光标所在单词
    const line =  document.lineAt(position);//光标所在行
    var in_hover = [];
    var x = line.text.indexOf("=");
    var yyy = line.text.substring(0,position.character);
    var hovercontent = '';
    if (x>-1) {
        in_hover = line.text.substring(x+1,line.text.length).split(".");
        console.log(in_hover)
        console.log(in_hover.length)
    }
    else
    {
        in_hover =  line.text.split(".");
    }
   
    if (in_hover.length>1) {
         //hovercontent = tips.tipsData[in_hover[0].tolowerCase()][word]
         var lower_word = in_hover[0].trim().toLowerCase(); 
         hovercontent = tips.tipsData[lower_word][0][word];
         //debugger
        console.log(hovercontent)
    }
  else {
       hovercontent = in_hover[0]
  }
   //console.log(in_hover)
    console.log(hovercontent)
    console.log('进入鼠标悬停方法');
    return new vscode.Hover(hovercontent);
}

module.exports = function (context) {
    // 注册鼠标悬停提示
    context.subscriptions.push(vscode.languages.registerHoverProvider('foxpro', {
        provideHover
    }));
};